package com.jiyun.purse.mapper;

import com.jiyun.pojo.purse.Purse;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface PurseMapper {

    @Select("select * from user_purse where user_id = #{userId} and bind_status = 1 and is_delete = 0")
    List<Purse> findPurse(Integer userId);

    @Select("select * from user_purse where id = #{id} and is_delete = 0")
    Purse findPurseById(Integer id);

    @Update("update user_purse set is_delete = 1 where id = #{id}")
    int deletePurse(Integer id);

    @Select("select * from user_purse where bank_card_number = #{bankCardNumber} and is_delete = 0")
    Purse selectCard(String bankCardNumber);

    @Update("update user_purse set bind_status = 1 where id = #{id}")
    void bindStatus(Integer id);

    @Insert("insert into user_purse" +
            "(bank_card_number,bank_icon,bank_name,bind_status,password_free_status,precedence_status,user_id,is_delete)" +
            " values (#{bankCardNumber},#{bankIcon},#{bankName},#{bindStatus},#{passwordFreeStatus},#{precedenceStatus},#{userId},#{isDelete})")
    void addCard(Purse purse);

    @Update("update user_purse set precedence_status = 0,password_free_status = 0 where id = #{id}")
    int updatePP(Integer id);

    @Update("update user_purse set precedence_status = 1 where id = #{id}")
    int updatePS1(Integer id);

    @Update("update user_purse set precedence_status = 0 where id = #{id}")
    void updatePS2(Integer id);

    @Select("select * from user_purse where precedence_status = 1 and is_delete = 0")
    Purse selectPS();

    @Update("update user_purse set password_free_status = 1 where id = #{id}")
    int updatePF(Integer id);

    @Update("update user_purse set password_free_status = 0 where id = #{id}")
    int updatePF1(Integer id);
}
